package com.huoshan.im.server;

import com.huoshan.im.server.config.ConfigHolder;
import com.huoshan.im.server.service.ServerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * 说明：作者很懒，什么都没留下
 * Created by 火山九日 on 2020-04-25 17:40
 */
@Slf4j
@SpringBootApplication
@EnableDiscoveryClient(autoRegister = false)
public class ChatServerApplication {

    @Resource
    private ChatServer chatServer;
    @Resource
    private ServerService serverService;

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(ChatServerApplication.class);
//        application.setWebApplicationType(WebApplicationType.NONE);
        ApplicationContext context = application.run(args);
        ConfigHolder.setApplicationContext(context);
    }

    @Component
    class Runner implements CommandLineRunner {

        @Override
        public void run(String... args) {
            chatServer.startup();
        }

        @PreDestroy
        public void shutdown() {
            log.info("shutdown server......");
            serverService.clearServerList();
            chatServer.shutdown();
        }

    }

}
